<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\AccessLog;

class Logger
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        # 记录用户调用日志
        $logger = new AccessLog();
        $logger->uid = \Session::get('uid');
        $logger->ip = $request->ip();
        $logger->method = $request->method();
        $logger->uri = $request->path();
        $logger->params = json_encode($request->all(), JSON_UNESCAPED_UNICODE);
        $logger->save();
        return $next($request);
    }
}
